package com.dyh.quickdemozwei.js;

import com.alibaba.fastjson.JSONObject;

/**
 * @Author: yhdong
 * @Date: 2021/9/16 16:26
 */


public class JsFieldValGetters {

    JsFieldValGetter simple = (jo,def)-> jo.get(def.getKey());

    JsFieldValGetter level = (jo,def)-> {
        String[] pathSp = def.getPath().split("/");
        JSONObject node = jo;
        for (String p : pathSp) {
            Object rawNode = node.get(p);
            if (rawNode==null)
                return null;
            node = (JSONObject)rawNode;
        }
        if (node==null)
            return null;
       return node.get(def.getKey());
    };

}
